<?php
/**
 * KayPaste
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * @category   KayPaste
 * @package    User
 * @subpackage Forms
 * @copyright  Copyright (c) 2007-2008 Robin Skoglund (http://robinsk.net/)
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author     Robin Skoglund
 */

/**
 * Imports
 */
require_once 'Zend/Controller/Action/HelperBroker.php';
require_once 'Zend/Form.php';
require_once 'Zend/Form/Element/Text.php';
require_once 'Zend/Form/Element/Password.php';
require_once 'Zend/Form/Element/Checkbox.php';
require_once 'Zend/Form/Element/Submit.php';

/**
 * User_Form_Forgot
 * 
 * This class represents a "I have forgot my password" form.
 *
 * @category   KayPaste
 * @package    User
 * @subpackage Forms
 * @copyright  Copyright (c) 2007-2008 Robin Skoglund (http://robinsk.net/)
 * @license    http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @author     Robin Skoglund
 */
class User_Form_Forgot extends Zend_Form
{
    const REGEX_USERNAME = '/^[a-z][a-z0-9@.\-_]*$/';
    
    /**
     * Initializes form
     * 
     */
    public function init()
    {
        $url = Zend_Controller_Action_HelperBroker::getStaticHelper('Url');
        $url = $url->url(
            array(
                'module'     => 'user',
                'controller' => 'login',
                'action'     => 'forgot-process'
            )
        );
        
        $this->setMethod('post')
             ->setAction($url)
             ->setAttrib('class', 'forgot');
        
        $username = new Zend_Form_Element_Text('username');
        $submit   = new Zend_Form_Element_Submit('submit');
        
        $this->addElement($username);
        $this->addElement($submit);
        
        $username->setRequired(true)
                 ->setLabel('Username / email')
                 ->setAttrib('class', 'text')
                 ->setAttrib('size', '32')
                 ->addFilters(array('StringTrim', 'StringToLower'))
                 ->addValidators(array(
                     array('NotEmpty', true),
                     array('StringLength', true, array(3, 64)),
                     array('regex', true, array(self::REGEX_USERNAME))
                 ));
        
        $submit->setLabel('Continue')
               ->setAttrib('class', 'button');
    }
}
